package ling.archives.cfg;


import com.ruoyi.common.constant.Constants;
import com.ruoyi.framework.web.service.PermissionService;
import ling.archives.common.FieldInit;
import lombok.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.util.Arrays;

@Service("ar")
public class ArchivesPowers extends FieldInit {

    @Resource
    PermissionService permissionService;
    public boolean any(String ...permissions) {
        if (permissions.length < 1) {
            return false;
        }
        var str = String.join(Constants.PERMISSION_DELIMETER, Arrays.asList(permissions));
        return permissionService.hasAnyPermi(str);
    }

    public ArchivesPowers(){
        // 初始化静态权限对象
        PowerStrSet(archive, null);
        PowerStrSet(approvalRecord, null);
        PowerStrSet(archiveContent, null);
        PowerStrSet(documentClass, null);
        PowerStrSet(borrowFile, null);
    }

    @Override
    public String fmtValByName(Field field, Object obj) {
        // 根据项目规范：权限字符串格式为 'ar:' + field name
        return "ar:archive:" + field.getName();
    }


    /** 审批记录 权限列表 */
    public final static ApprovalRecordPower approvalRecord=new ApprovalRecordPower();
    @NoArgsConstructor(force = true)
    public static   class ApprovalRecordPower {
        public String list ;
        public String export ;
        public String query ;
        public String add ;
        public String edit ;
        public String remove ;
    }
    /** 卷宗 权限列表 */
    public final static ArchivePower archive=new ArchivePower();
    @NoArgsConstructor(force = true)
    public static   class ArchivePower {
        public String list ;
        public String export ;
        public String query ;
        public String add ;
        public String edit ;
        public String remove ;
        public String importData;
        public String fileng;
    }
    /** 卷宗内容 权限列表 */
    public final static ArchiveContentPower archiveContent=new ArchiveContentPower();
    @NoArgsConstructor(force = true)
    public static   class ArchiveContentPower {
        public String list ;
        public String export ;
        public String query ;
        public String add ;
        public String edit ;
        public String remove ;
    }
    /** 文件分类 权限列表 */
    public final static DocumentClassPower documentClass=new DocumentClassPower();
    @NoArgsConstructor(force = true)
    public static   class DocumentClassPower {
        public String list ;
        public String export ;
        public String query ;
        public String add ;
        public String edit ;
        public String remove ;
    }

    /**
     * 借阅 权限列表
     */
    public final static BorrowFilePower borrowFile = new BorrowFilePower();

    @NoArgsConstructor(force = true)
    public static class BorrowFilePower {
        public String list;
        public String export;
        public String query;
        public String add;
        public String edit;
        public String remove;
    }
}
